From 09e98378cf70ec51a0312adc8cdfc18f87b542ba Mon Sep 17 00:00:00 2001 From: Hollis Blanchard Date: Fri, 2 Mar 2007 17:08:04 -0600 Subject: [PATCH] [POWERPC][XEN][LIBXC] Make xc_linux_build() use populate_physmap() - populate_physmap() is the only way to invoke guest_physmap_{add/remove}_page(), which populate our new p2m table. - To use it, we must to specify an array of PFNs where the new MFNs will be mapped. - Split out alloc_memory() from xc_linux_build(). - Fix memory free path in xc_linux_build(). Signed-off-by: Ryan Harper Signed-off-by: Hollis Blanchard --HG-- extra : transplant_source : %9F%E6%FE%88%A6%A1%A2%88l%24%F2%AFvMf%3C%05%AF%DAU --- tools/libxc/powerpc64/xc_linux_build.c | 87 ++++++++++++++++++-------- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/tools/libxc/powerpc64/xc_linux_build.c b/tools/libxc/powerpc64/xc_linux_build.c index 8c58f31222..f6416dfefb 100644 --- a/tools/libxc/powerpc64/xc_linux_build.c +++ b/tools/libxc/powerpc64/xc_linux_build.c @@ -39,6 +39,10 @@ #include "utils.h" #include "mk_flatdevtree.h" +/* Use 16MB extents to match PowerPC's large page size. */ +#define EXTENT_SHIFT 24 +#define EXTENT_ORDER (EXTENT_SHIFT - PAGE_SHIFT) + #define INITRD_ADDR (24UL << 20) #define DEVTREE_ADDR (16UL << 20) @@ -150,6 +154,50 @@ static int check_memory_config(int rma_log, unsigned int mem_mb) return 1; } +static int alloc_memory(int xc_handle, domid_t domid, ulong nr_pages, + ulong rma_pages) +{ + xen_pfn_t *extent_pfn_arry; + ulong nr_extents; + ulong start_pfn = rma_pages; + int i; + int j; + int rc = 0; + + nr_extents = (nr_pages - rma_pages) >> EXTENT_ORDER; + DPRINTF("allocating memory in %lu chunks of %luMB\n", nr_extents, + 1UL >> (20 - EXTENT_ORDER)); + + /* populate_physmap requires an array of PFNs that determine where the + * guest mapping of the new MFNs. */ + extent_pfn_arry = malloc((1<> extent_order; - DPRINTF("allocating memory in %llu chunks of %luMB\n", nr_extents, - (((1 << extent_order) >> 10) * PAGE_SIZE) >> 10); - - /* now allocate the remaining memory as large-order allocations */ - DPRINTF("increase_reservation(%u, %llu, %u)\n", domid, nr_extents, extent_order); - if (xc_domain_memory_increase_reservation(xc_handle, domid, nr_extents, - extent_order, 0, NULL)) { + /* Get the MFN mapping (for RMA only -- we only load data into the RMA). */ + if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) { rc = -1; goto out; } - if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) { - rc = -1; + /* Allocate the non-RMA memory. */ + rc = alloc_memory(xc_handle, domid, nr_pages, rma_pages); + if (rc) { goto out; } + /* Load kernel. */ DPRINTF("loading image '%s'\n", image_name); if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) { rc = -1; @@ -237,6 +272,7 @@ int xc_linux_build(int xc_handle, } kern_addr = 0; + /* Load initrd. */ if (initrd_name && initrd_name[0] != '\0') { DPRINTF("loading initrd '%s'\n", initrd_name); if (load_initrd(xc_handle, domid, page_array, initrd_name, @@ -249,7 +285,7 @@ int xc_linux_build(int xc_handle, /* fetch the current shadow_memory value for this domain */ op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION; if (xc_shadow_control(xc_handle, domid, op, NULL, 0, - &shadow_mb, 0, NULL) < 0 ) { + &shadow_mb, 0, NULL) < 0) { rc = -1; goto out; } @@ -284,16 +320,17 @@ int xc_linux_build(int xc_handle, devtree_addr, devtree.bph->totalsize)) { DPRINTF("couldn't load flattened device tree.\n"); rc = -1; - goto out; + goto out2; } if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) { rc = -1; - goto out; + goto out2; } -out: +out2: free_devtree(&devtree); +out: free_page_array(page_array); return rc; } -- 2.30.2